LOCAL_PATH := $(call my-dir)
commonFlags := \
    -D_GNU_SOURCE \
    -DDEBUG_EXPORT_ERROR_STRINGS=1 \
    -DFRAMEWORK_STYLE_INCLUDES=0 \
    -DTARGET_HAS_NATIVE_INT128=0 \
    -DTARGET_NEEDS_NATURAL_ALIGNMENT=1 \
    -DAES_UTILS_USE_GLADMAN_AES=1 \
    -DUSE_VIA_ACE_IF_PRESENT=0 \
    -DTARGET_HAS_MD5_UTILS=1 \
    -DTARGET_HAS_SHA_UTILS=1 \
    -DTARGET_NO_OPENSSL=1 \
    -DTARGET_HAS_LIBTOMMATH=1 \
    -DAES_UTILS_HAS_GLADMAN_GCM=0 \
    -DMFI_AUTH_DEVICE_PATH=\"/dev/i2c-2\"
    -DMFI_AUTH_DEVICE_ADDRESS=0x10 \
    -D__STDC_LIMIT_MACROS=1 \
    -DCFL_BINARY_PLISTS=1 \
    -DCFLITE_ENABLED=1 \
    -DDEBUG_CF_OBJECTS_ENABLED=1 \
    -DDEBUG=1 \
    -DAIRPLAY_SCREEN=1 \
	#-DMFI_AUTH_DEVICE_PATH=\"/dev/i2c-1\"
	#-DMFI_AUTH_DEVICE_PATH=\"/dev/i2c-1\"
# ====================================================================
# libCoreUtils
# ====================================================================
include $(CLEAR_VARS)

LOCAL_MODULE := libCoreUtils
# includes from AOSP
LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/AccessorySDK/External/Curve25519 \
    $(LOCAL_PATH)/AccessorySDK/External/Ed25519 \
    $(LOCAL_PATH)/AccessorySDK/External/GladmanAES \
    $(LOCAL_PATH)/AccessorySDK/External/LibTomMath \
    $(LOCAL_PATH)/AccessorySDK/External/Small25519 \
    $(LOCAL_PATH)/AccessorySDK/External/SRP \
    $(LOCAL_PATH)/AccessorySDK/Support/ \
    $(LOCAL_PATH)/include \

LOCAL_SRC_FILES := \
    AccessorySDK/Support/AESUtils.c \
    AccessorySDK/Support/AsyncConnection.c \
    AccessorySDK/Support/AtomicUtils.c \
    AccessorySDK/Support/BonjourBrowser.c \
    AccessorySDK/Support/CFCompat.c \
    AccessorySDK/Support/CFLite.c \
    AccessorySDK/Support/CFLiteBinaryPlist.c \
    AccessorySDK/Support/CFLitePreferencesFile.c \
    AccessorySDK/Support/CFLiteRunLoopSelect.c \
    AccessorySDK/Support/CFUtils.c \
    AccessorySDK/Support/ChaCha20Poly1305.c \
    AccessorySDK/Support/CommandLineUtils.c \
    AccessorySDK/Support/DataBufferUtils.c \
    AccessorySDK/Support/DebugIPCUtils.c \
    AccessorySDK/Support/DebugServices.c \
    AccessorySDK/Support/DispatchLite.c \
    AccessorySDK/Support/HTTPClient.c \
    AccessorySDK/Support/HTTPMessage.c \
    AccessorySDK/Support/HTTPServer.c \
    AccessorySDK/Support/HTTPUtils.c \
    AccessorySDK/Support/KeychainLiteFile.c \
    AccessorySDK/Support/KeychainUtils.c \
    AccessorySDK/Support/LogUtils.c \
    AccessorySDK/Support/MathUtils.c \
    AccessorySDK/Support/MFiSAP.c \
    AccessorySDK/Support/MFiServerPlatformLinux.c \
    AccessorySDK/Support/MiscUtils.c \
    AccessorySDK/Support/NetTransportChaCha20Poly1305.c \
    AccessorySDK/Support/NetUtils.c \
    AccessorySDK/Support/NetworkChangeListener.c \
    AccessorySDK/Support/PairingUtils.c \
    AccessorySDK/Support/PrintFUtils.c \
    AccessorySDK/Support/RandomNumberUtils.c \
    AccessorySDK/Support/SHAUtils.c \
    AccessorySDK/Support/SRPUtils.c \
    AccessorySDK/Support/StringUtils.c \
    AccessorySDK/Support/ThreadUtils.c \
    AccessorySDK/Support/TickUtils.c \
    AccessorySDK/Support/TimeUtils.c \
    AccessorySDK/Support/TLVUtils.c \
    AccessorySDK/Support/URLUtils.c \
    AccessorySDK/Support/utfconv.c \
    AccessorySDK/Support/UUIDUtils.c\

LOCAL_SRC_FILES += \
    AccessorySDK/External/Curve25519/curve25519-donna.c\

LOCAL_SRC_FILES += \
    Sources/airplayutil.c \

LOCAL_SRC_FILES += \
    AccessorySDK/External/Small25519/Small25519.c\

LOCAL_SRC_FILES += \
    AccessorySDK/External/Ed25519/ed25519.c\

LOCAL_SRC_FILES += \
    AccessorySDK/External/GladmanAES/aes_modes.c \
    AccessorySDK/External/GladmanAES/aescrypt.c \
    AccessorySDK/External/GladmanAES/aeskey.c \
    AccessorySDK/External/GladmanAES/aestab.c \

LOCAL_SRC_FILES += \
    AccessorySDK/External/LibTomMath/bn_fast_mp_invmod.c \
    AccessorySDK/External/LibTomMath/bn_fast_mp_montgomery_reduce.c \
    AccessorySDK/External/LibTomMath/bn_fast_s_mp_mul_digs.c \
    AccessorySDK/External/LibTomMath/bn_fast_s_mp_mul_high_digs.c \
    AccessorySDK/External/LibTomMath/bn_fast_s_mp_sqr.c \
    AccessorySDK/External/LibTomMath/bn_mp_2expt.c \
    AccessorySDK/External/LibTomMath/bn_mp_abs.c \
    AccessorySDK/External/LibTomMath/bn_mp_add_d.c \
    AccessorySDK/External/LibTomMath/bn_mp_add.c \
    AccessorySDK/External/LibTomMath/bn_mp_clamp.c \
    AccessorySDK/External/LibTomMath/bn_mp_clear_multi.c \
    AccessorySDK/External/LibTomMath/bn_mp_clear.c \
    AccessorySDK/External/LibTomMath/bn_mp_cmp_d.c \
    AccessorySDK/External/LibTomMath/bn_mp_cmp_mag.c \
    AccessorySDK/External/LibTomMath/bn_mp_cmp.c \
    AccessorySDK/External/LibTomMath/bn_mp_cnt_lsb.c \
    AccessorySDK/External/LibTomMath/bn_mp_copy.c \
    AccessorySDK/External/LibTomMath/bn_mp_count_bits.c \
    AccessorySDK/External/LibTomMath/bn_mp_div_2.c \
    AccessorySDK/External/LibTomMath/bn_mp_div_2d.c \
    AccessorySDK/External/LibTomMath/bn_mp_div_3.c \
    AccessorySDK/External/LibTomMath/bn_mp_div_d.c \
    AccessorySDK/External/LibTomMath/bn_mp_div.c \
    AccessorySDK/External/LibTomMath/bn_mp_dr_is_modulus.c \
    AccessorySDK/External/LibTomMath/bn_mp_dr_reduce.c \
    AccessorySDK/External/LibTomMath/bn_mp_dr_setup.c \
    AccessorySDK/External/LibTomMath/bn_mp_exch.c \
    AccessorySDK/External/LibTomMath/bn_mp_exptmod_fast.c \
    AccessorySDK/External/LibTomMath/bn_mp_exptmod.c \
    AccessorySDK/External/LibTomMath/bn_mp_grow.c \
    AccessorySDK/External/LibTomMath/bn_mp_init_copy.c \
    AccessorySDK/External/LibTomMath/bn_mp_init_multi.c \
    AccessorySDK/External/LibTomMath/bn_mp_init_size.c \
    AccessorySDK/External/LibTomMath/bn_mp_init.c \
    AccessorySDK/External/LibTomMath/bn_mp_invmod_slow.c \
    AccessorySDK/External/LibTomMath/bn_mp_invmod.c \
    AccessorySDK/External/LibTomMath/bn_mp_karatsuba_mul.c \
    AccessorySDK/External/LibTomMath/bn_mp_karatsuba_sqr.c \
    AccessorySDK/External/LibTomMath/bn_mp_lshd.c \
    AccessorySDK/External/LibTomMath/bn_mp_mod_2d.c \
    AccessorySDK/External/LibTomMath/bn_mp_mod_d.c \
    AccessorySDK/External/LibTomMath/bn_mp_mod.c \
    AccessorySDK/External/LibTomMath/bn_mp_montgomery_calc_normalization.c \
    AccessorySDK/External/LibTomMath/bn_mp_montgomery_reduce.c \
    AccessorySDK/External/LibTomMath/bn_mp_montgomery_setup.c \
    AccessorySDK/External/LibTomMath/bn_mp_mul_2.c \
    AccessorySDK/External/LibTomMath/bn_mp_mul_2d.c \
    AccessorySDK/External/LibTomMath/bn_mp_mul_d.c \
    AccessorySDK/External/LibTomMath/bn_mp_mul.c \
    AccessorySDK/External/LibTomMath/bn_mp_mulmod.c \
    AccessorySDK/External/LibTomMath/bn_mp_prime_is_divisible.c \
    AccessorySDK/External/LibTomMath/bn_mp_prime_is_prime.c \
    AccessorySDK/External/LibTomMath/bn_mp_prime_miller_rabin.c \
    AccessorySDK/External/LibTomMath/bn_mp_prime_rabin_miller_trials.c \
    AccessorySDK/External/LibTomMath/bn_mp_read_unsigned_bin.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k_l.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k_setup_l.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k_setup.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce_is_2k_l.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce_is_2k.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce_setup.c \
    AccessorySDK/External/LibTomMath/bn_mp_reduce.c \
    AccessorySDK/External/LibTomMath/bn_mp_rshd.c \
    AccessorySDK/External/LibTomMath/bn_mp_set_int.c \
    AccessorySDK/External/LibTomMath/bn_mp_set.c \
    AccessorySDK/External/LibTomMath/bn_mp_sqr.c \
    AccessorySDK/External/LibTomMath/bn_mp_sqrmod.c \
    AccessorySDK/External/LibTomMath/bn_mp_sub_d.c \
    AccessorySDK/External/LibTomMath/bn_mp_sub.c \
    AccessorySDK/External/LibTomMath/bn_mp_to_unsigned_bin.c \
    AccessorySDK/External/LibTomMath/bn_mp_toom_mul.c \
    AccessorySDK/External/LibTomMath/bn_mp_toom_sqr.c \
    AccessorySDK/External/LibTomMath/bn_mp_unsigned_bin_size.c \
    AccessorySDK/External/LibTomMath/bn_mp_zero.c \
    AccessorySDK/External/LibTomMath/bn_prime_tab.c \
    AccessorySDK/External/LibTomMath/bn_reverse.c \
    AccessorySDK/External/LibTomMath/bn_s_mp_add.c \
    AccessorySDK/External/LibTomMath/bn_s_mp_exptmod.c \
    AccessorySDK/External/LibTomMath/bn_s_mp_mul_digs.c \
    AccessorySDK/External/LibTomMath/bn_s_mp_mul_high_digs.c \
    AccessorySDK/External/LibTomMath/bn_s_mp_sqr.c \
    AccessorySDK/External/LibTomMath/bn_s_mp_sub.c \
    AccessorySDK/External/LibTomMath/bncore.c

LOCAL_SRC_FILES += \
    AccessorySDK/External/SRP/cstr.c \
    AccessorySDK/External/SRP/srp.c \
    AccessorySDK/External/SRP/srp6_client.c \
    AccessorySDK/External/SRP/srp6_server.c \
    AccessorySDK/External/SRP/t_math.c

LOCAL_CFLAGS := \
    $(commonFlags) \

# LOCAL_STATIC_LIBRARIES := libc libcutils liblog
LOCAL_LDLIBS := -llog
APP_ALLOW_MISSING_DEPS := true
LOCAL_SHARED_LIBRARIES := \
    libzxmdnssd \

LOCAL_LDFLAGS := -Wl,--unresolved-symbols=ignore-all, \

include $(BUILD_SHARED_LIBRARY)
# ====================================================================
# libAirPlay
# libCarPlay
# ====================================================================
ifeq (1,1)
include $(CLEAR_VARS)
LOCAL_MODULE := libCarPlay

# includes from AppleCarPlay_CommunicationPlugin_R14G17
LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/AccessorySDK/External/Curve25519 \
    $(LOCAL_PATH)/AccessorySDK/External/Ed25519 \
    $(LOCAL_PATH)/AccessorySDK/External/GladmanAES \
    $(LOCAL_PATH)/AccessorySDK/External/LibTomMath \
    $(LOCAL_PATH)/AccessorySDK/External/SRP \
    $(LOCAL_PATH)/AccessorySDK/Support/ \
    $(LOCAL_PATH)/Platform \
    $(LOCAL_PATH)/Sources \
    $(LOCAL_PATH)/Support \
    $(LOCAL_PATH)/Examples\
    $(LOCAL_PATH)/include \
    $(LOCAL_PATH)/../iap2CPP/include \
    $(LOCAL_PATH)/../iap2CPP/include/util\

# includes from AOSP
#LOCAL_C_INCLUDES += \
#    Z:\work\build_system\android\external\mdnsresponder\mDNSShared \
#    Z:\work\build_system\android\external\aac\libAACdec\include \
#    Z:\work\build_system\android\external\aac\libAACenc\include \
#    Z:\work\build_system\android\external\aac\libSYS\include   \
#    Z:\work\build_system\android\frameworks\av\media\libaudioclient \
#    Z:\work\build_system\android\frameworks\av\media\libaaudio\include

#LOCAL_C_INCLUDES += \
#	Z:\work\build_system\android\external\tinyalsa\include
#LOCAL_C_INCLUDES += \
#	Z:\work\Semidrive4.0\build_system\android\external\mdnsresponder\mDNSShared \
#	Z:\work\Semidrive4.0\build_system\android\external\aac\libAACdec\include \
#	Z:\work\Semidrive4.0\build_system\android\external\aac\libAACenc\include \
#	Z:\work\Semidrive4.0\build_system\android\external\aac\libSYS\include \
#	Z:\work\Semidrive4.0\build_system\android\external\libSYS\include \
#	Z:\work\Semidrive4.0\build_system\android\frameworks\av\media\libaudioclient \
#	Z:\work\Semidrive4.0\build_system\android\frameworks\av\media\libaaudio\include \

LOCAL_SRC_FILES := \
    Sources/AirPlayReceiverPOSIX.c \
    Sources/AirPlayReceiverServer.c \
    Sources/AirPlayReceiverSession.c \
    Sources/AirPlayReceiverSessionAudio.c \
    Sources/AirPlayReceiverSessionScreen.c \
    Sources/AirPlayUtils.c \
    Sources/AirTunesClock.c \
    Sources/APReceiverStatsCollector.c \
    Sources/APSRTPJitterBuffer.c\
    Sources/APSRTPPacketHandler.c\
    Sources/CarPlayControlClient.c\
    Sources/SimpleQueue.c \

# Audio / Screen
LOCAL_SRC_FILES += \
	Platform/AudioUtilsStub.c
	#Examples/AudioUtils_Android.c
	#Support/AudioUtilsDLL.c
	#Examples/AudioUtilsALSA.c
	#Platform/AudioUtilsStub.c
	#Examples/AudioUtilsALSA.c



LOCAL_SRC_FILES += \
	Examples/CarPlayInterface.c \
    Platform/ScreenUtilsStub.c \


LOCAL_SRC_FILES += \
    Examples/AudioConverter_FDKAAC_OPUS.c   \
    Examples/genericStds.cpp

LOCAL_SRC_FILES += \
    Platform/HIDKnob.c \
    Platform/HIDMediaButtons.c \
    Platform/HIDProximity.c \
    Platform/HIDTelephony.c \
    Platform/HIDTouchpad.c \
    Platform/HIDTouchScreen.c \

LOCAL_CFLAGS := \
    $(commonFlags) \

LOCAL_LDFLAGS := -Wl,--unresolved-symbols=ignore-all \

LOCAL_LDLIBS := -llog
APP_ALLOW_MISSING_DEPS := true

LOCAL_SHARED_LIBRARIES := \
    libCoreUtils \
    libiap2CPP \
    libzxmdnssd \
    libfdk-aac
    #libaaudio

#	libAudioStream


include $(BUILD_SHARED_LIBRARY)

endif

# ====================================================================
# AppleCarplay
# ====================================================================
ifeq (1,1)
include $(CLEAR_VARS)

LOCAL_MODULE := libCarplayInterface

LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/Platform \
    $(LOCAL_PATH)/AccessorySDK/Support/ \
    $(LOCAL_PATH)/AccessorySDK/External/Curve25519 \
    $(LOCAL_PATH)/AccessorySDK/External/Ed25519 \
    $(LOCAL_PATH)/AccessorySDK/External/GladmanAES \
    $(LOCAL_PATH)/AccessorySDK/External/LibTomMath \
    $(LOCAL_PATH)/AccessorySDK/External/SRP \
    $(LOCAL_PATH)/Sources  \
    $(LOCAL_PATH)/Support \
    $(LOCAL_PATH)/Examples \
    $(LOCAL_PATH)/include \
    $(LOCAL_PATH)/../iap2CPP/include/util \
    $(LOCAL_PATH)/../iap2CPP/include \

LOCAL_SRC_FILES := \
    Examples/AppleCarPlay_AppStub.c \
    Examples/iAP2_AppStub.c \
    Examples/carplayExt.cpp \
    Examples/CarPlayInterface.c\

LOCAL_CFLAGS := \
    $(commonFlags) \

LOCAL_CFLAGS += -Wno-non-virtual-dtor

LOCAL_LDLIBS := -llog
APP_ALLOW_MISSING_DEPS := true

LOCAL_SHARED_LIBRARIES := \
    libiap2CPP \
    libzxusb1.0 \
    libCoreUtils\
    libCarPlay \

include $(BUILD_SHARED_LIBRARY)

# ====================================================================
# AppleCarplay
# ====================================================================
#include $(CLEAR_VARS)

#LOCAL_MODULE:= AppleCarplayTest

#LOCAL_C_INCLUDES := \
#    $(LOCAL_PATH)/Examples \
#    $(LOCAL_PATH)/include \
#
#LOCAL_SRC_FILES := \
#    Examples/carplaytest.cpp \
#
#LOCAL_CFLAGS := \
#    $(commonFlags) \
#
##LOCAL_LDLIBS := -lc++
#
#
#LOCAL_LDFLAGS  := -Wl,-rpath-link=$(LOCAL_PATH)/lib/$(TARGET_ARCH_ABI)
#
#LOCAL_CFLAGS += -Wno-non-virtual-dtor \
#
#
#LOCAL_SHARED_LIBRARIES := \
#    libiap2CPP \
#    liblog \
#    libusb \
#    libCoreUtils\
#    libCarPlay \
#    libCarplayInterface \
#
#
##APP_ALLOW_MISSING_DEPS := true
#
#include $(BUILD_EXECUTABLE)
endif
